<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 *
 * 创建时间：2021-10-31 18:59:50
 *
 * 项目：/levfm  -  $  - Form_levfm_formsHelper.php
 *
 * 作者：{{AUTO GENERATE}}
 */

//此文件使用程序自动生成，下次生成时【不会】覆盖。
//在这里可以补充、完善你的程序逻辑

namespace modules\levfm\table\form\Form_levfm_forms;

use Lev;
use modules\levfm\table\form\Form_levfm_fields\Form_levfm_fields;
use modules\levfm\table\form\Form_levfm_forms\_gen\BaseForm_levfm_forms;
use modules\levfm\table\LevfmFields;
use modules\levfm\table\LevfmForms;
use modules\levfm\widgets\inputs\inputtypes\tablesFormType;

!defined('INLEV') && exit('Access Denied LEV');

class BaseForm_levfm_formsMiddle extends BaseForm_levfm_forms
{

    public static $tableName = '{{%levfm_forms}}';

    public static function saveForm($formPre = 'datax', $route = '', $form = null, $upData = null, $upDataForce = null, $opInfo = null)
    {
        return parent::saveForm($formPre, $route, $form, $upData, $upDataForce, $opInfo); // TODO: Change the autogenerated stub

    }

    public static function inputs($iden = '', $keyfield = '', $classify = null)
    {
        $inputs = parent::inputs($iden, $keyfield, $classify); // TODO: Change the autogenerated stub
        //$_GET['formid'] = floatval(Lev::GPv('opid'));
        //$inputs['fields']['settings']['tablesForm'] = Form_levfm_fields::tabInputs()[0];
        return $inputs;
    }

    /**
     * 额外的表单字段，不会存入数据库
     * @return array
     */
    public static function extInputs()
    {
        //return parent::extInputs(); // TODO: Change the autogenerated stub
        $inputs = [];

        Lev::GPv('setup') == 20 &&
        $inputs = array(
            '_createFormDataTableForce'                 => array(
                'moduleidentifier' => 'levfm',
                'classify'         => 'levfm_forms',
                'title'            => '强制创建数据表',
                'placeholder'      => '开启后强制执行创建，否则不执行数据库建表动作',
                'inputname'        => '_createFormDataTableForce',
                'inputtype'        => 'radio',
                'inputvalue'       => '1',
                'settings'         => '',
                'displayorder'     => '0',
                'status'           => '1',
            ),
        );
        return $inputs;
    }

    public static function headerHtm()
    {
        //return parent::headerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义headerHtm：文件位置：'.__DIR__ . '/Form_levfm_forms.php'.'</tips>';
    }

    public static function footerHtm()
    {
        return parent::footerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义footerHtm</tips>';
    }

    public static function footerFormInnerHtm()
    {
        return parent::footerFormInnerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义footerFormInnerHtm</tips>';
    }

    public static function getFormid() {
        return floatval(Lev::GPv('opid')) ?: floatval(Lev::GPv('formid'));
    }

    public static function setsettings___typeSearchs() {
        $formid = static::getFormid();
        return LevfmFields::getTypeSearchs($formid);
    }

    public static function setsettings___srhkeyType() {
        return LevfmForms::srhkeyType();
    }

    public static function setShowType() {
        return LevfmForms::listShowType();
    }

    public static function setsettings___listShowFields() {
        static $arr;

        if (!isset($arr)) {
            $arr = [];
            $res = LevfmFields::getFormidFields(static::getFormid());
            foreach ($res as $v) {
                $arr[$v['inputname'] ?: LevfmForms::tableFieldname($v['id'])] = $v['title'];
            }
        }
        return $arr;
    }

    public static function setsettings___totalitem() {
        return static::setsettings___listShowFields();
    }

    public static function setformTmp() {
        return LevfmForms::formTmp();
    }

    public static function setname() {
        return LevfmForms::setname();
    }

}


class Form_levfm_forms extends BaseForm_levfm_formsMiddle {

    public static function allColumns()
    {
        return parent::allColumns(); // TODO: Change the autogenerated stub
    }

    public static function safeColumnsInpus($columns)
    {
        return parent::safeColumnsInpus($columns); // TODO: Change the autogenerated stub
    }

    public static function setFormSettings($settings, $result = [])
    {
        return parent::setFormSettings($settings, $result); // TODO: Change the autogenerated stub
    }

    public static function saveInputs($datas, $where = [], $inId = false, $tables = [], $inputs = [], $formSet = true, $tablesFormData = [])
    {
        return parent::saveInputs($datas, $where, $inId, $tables, $inputs, $formSet, $tablesFormData); // TODO: Change the autogenerated stub
    }

    public static function getNextSetup()
    {
        return parent::getNextSetup(); // TODO: Change the autogenerated stub
    }

    public static function inputsSetup()
    {
        return parent::inputsSetup(); // TODO: Change the autogenerated stub
    }

    public static function setupDesc()
    {
        //return parent::setupDesc(); // TODO: Change the autogenerated stub
        return [
            '1' => '表单基本信息',
            '3' => '分类搜索',
            '5' => '表单权限设置',
            '10' => '表单字段管理<svg class="icon"><use xlink:href="#fa-huoj"></use></svg>',
            '15' => '统计字段数据',
            //'20' => '表单数据存储表管理',
        ];
    }

    /**
     * 表单所有权限字段
     * @return mixed
     */
    public static function formAccessInputs() {
        return static::inputsSetup()[5];
    }
}